package com.samebuilding.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.samebuilding.dao.ActivitySmallTypeDAO;
import com.samebuilding.domain.ActivitySmalltype;

public class ActivitySmallTypeDAOImpl extends
		GenericDAOImpl<ActivitySmalltype, Integer> implements
		ActivitySmallTypeDAO {

	private static final String FIND_BY_SMALLTYPE = "from ActivitySmalltype smalltype where smalltype.activityBigtype.bigtypeId = ?";
	
	
	@SuppressWarnings("unchecked")
	public List<ActivitySmalltype> findByBigType(final int bigTypeId) {

		List list = (List<ActivitySmalltype>)getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query = session.createQuery(FIND_BY_SMALLTYPE);
				query.setInteger(0, bigTypeId);
				List<ActivitySmalltype> list = query.list();
				return list;
			}
		});
		return list;
	}


}
